#include "OutputMessageBufferHolder.h"

namespace AlgoTrading
{
	namespace ConnectionLibrary
	{
		
		OutputMessageBufferHolder::OutputMessageBufferHolder()
			: messageLength(new ::google::protobuf::uint32)
			, streamBuf(new boost::asio::streambuf())
			, stream(new std::ostream(streamBuf.get()))
		{
		}

		::google::protobuf::uint32* OutputMessageBufferHolder::GetMessageLength()
		{
			return messageLength.get();
		}

		boost::asio::const_buffer OutputMessageBufferHolder::GetMessageBuffer()
		{
			return streamBuf->data();
		}

		std::ostream& OutputMessageBufferHolder::GetOutputStream()
		{
			return *stream;
		}

		void OutputMessageBufferHolder::ParseMessageLength()
		{
			*(messageLength.get()) = streamBuf->size();
		}
	}
}